// src/entities/alert.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
import { Server } from './server.entity';
import { Project } from './project.entity';

@Entity('alerts')
export class Alert {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100 })
  title: string;

  @Column({
    type: 'enum',
    enum: ['critical', 'high', 'medium', 'low'],
    default: 'low',
  })
  level: string;

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({
    type: 'enum',
    enum: ['pending', 'processing', 'resolved'],
    default: 'pending',
  })
  status: string;

  @ManyToOne(() => Server, (s) => s.alerts, { nullable: true })
  server: Server;

  @ManyToOne(() => Project, (p) => p.alerts, { nullable: true })
  project: Project;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  triggeredAt: Date;

  @Column({ type: 'timestamp', nullable: true })
  resolvedAt: Date;
}
